package com.example.mybatis.Controller;

import com.example.mybatis.dao.UserMapper;
import com.example.mybatis.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController()
@RequestMapping("user")
public class HelloWorld {
    @Autowired
    UserMapper userMapper;

    @GetMapping("all")
    public List<User> getUsers(){
      return userMapper.getUsers();
    }

   @GetMapping("add")
    public int insert(){
        User user = new User();
        user.setId(new Random().nextInt(100));
        user.setName("lisi");
        user.setPassword("abc123");
        return userMapper.insertUser(user);
    }

    @GetMapping("ch")
    public int testUpdate(){
        return userMapper.updateUser("abc11111",23);
    }
}
